﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royalsoft.Common;

namespace NJL.WebManage.SystemAdmin
{
    public partial class EditWebsite :BasePage
    {
        private readonly NJL.BLL.NJL_SYS_BASE bll = new BLL.NJL_SYS_BASE();
        NJL.Model.NJL_SYS_BASE model;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                model = bll.GetModel(Request.QueryString["id"]);
                if (model != null)
                {
                    txtName.Text = model.WEBSITE_NAME;
                    txtCode.Text = model.WEBSITE_CODE;
                    txtDomain.Text = model.WEBSITE_DOMAIN;
                    txtTitle.Text = model.WEBSITE_TITLE;
                    txtKeywords.Text = model.WEBSITE_KEYWORDS;
                    txtDesc.Text = model.WEBSITE_DESCRIPTION;
                    txtAdmin.Text = model.WEBSITE_ADMIN;
                    txtInsertCode.Text = model.WEBSITE_INSERT_CODE;

                    txtContact.Text = model.WEBSITE_CONTACT;
                    txtContactTel.Text = model.WEBSITE_CONTACT_TEL;
                    txtContactQQ.Text = model.WEBSITE_CONTACT_QQ;
                    txtContactEmail.Text = model.WEBSITE_CONTACT_EMAIL;
                    txtContactIntro.Text = model.WEBSITE_CONTACT_INTRO;
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            model = bll.GetModel(Request.QueryString["id"]);
            model.WEBSITE_NAME = txtName.Text.Trim();
            model.WEBSITE_CODE = txtCode.Text.Trim();
            model.WEBSITE_DOMAIN = txtDomain.Text.Trim();
            model.WEBSITE_TITLE = txtTitle.Text.Trim();
            model.WEBSITE_DESCRIPTION = txtDesc.Text.Trim();
            model.WEBSITE_KEYWORDS = txtKeywords.Text.Trim();
            model.WEBSITE_ADMIN = txtAdmin.Text.Trim();
            model.WEBSITE_INSERT_CODE = txtInsertCode.Text.Trim();

            model.WEBSITE_CONTACT = txtContact.Text.Trim();
            model.WEBSITE_CONTACT_TEL = txtContactTel.Text.Trim();
            model.WEBSITE_CONTACT_QQ = txtContactQQ.Text.Trim();
            model.WEBSITE_CONTACT_EMAIL = txtContactEmail.Text.Trim();
            model.WEBSITE_CONTACT_INTRO = txtContactIntro.Text.Trim();

            model.UPDATE_DATE_TIME = DateTime.Now;
            model.UPDATE_USER_ID = base.USER_ID;
            model.UPDATE_USER_NAME = base.USER_NAME;
            if (bll.Update(model))
            {
                MessageBox.ShowAndRedirect(this, "更新成功", "EditWebsite.aspx?id="+Request.QueryString["id"]);
            }
        }
    }
}